#!/bin/sh

cd "$(dirname "$0")"

version=$(grep '<Version>' < ../source/TS.NET.Engine/TS.NET.Engine.csproj | sed 's/.*<Version>\(.*\)<\/Version>/\1/')

if test -f ../builds/TS.NET.Engine/osx-arm64/thunderscope.yaml; then
  cp ../builds/TS.NET.Engine/osx-arm64/thunderscope.yaml ../thunderscope.yaml
fi

if test -f ../builds/TS.NET.Engine/osx-arm64/thunderscope-calibration.json; then
  cp ../builds/TS.NET.Engine/osx-arm64/thunderscope-calibration.json ../thunderscope-calibration.json
fi

if test -f ../builds/TS.NET.Engine/osx-arm64/thunderscope-appsettings.json; then
  cp ../builds/TS.NET.Engine/osx-arm64/thunderscope-appsettings.json ../thunderscope-appsettings.json
fi

if test -f ../builds/TS.NET.Engine/osx-arm64/libtslitex.so; then
  cp ../builds/TS.NET.Engine/osx-arm64/libtslitex.so ../libtslitex.so
fi

dotnet publish ../source/TS.NET.Engine/TS.NET.Engine.csproj -r osx-arm64 -c Release --self-contained /p:PublishSingleFile=true /p:PublishTrimmed=true /p:IncludeNativeLibrariesForSelfExtract=true --output ../builds/TS.NET.Engine/osx-arm64

if test -f ../thunderscope.yaml; then
  cp ../thunderscope.yaml ../builds/TS.NET.Engine/osx-arm64/thunderscope.yaml
  rm ../thunderscope.yaml
fi

if test -f ../thunderscope-calibration.json; then
  cp ../thunderscope-calibration.json ../builds/TS.NET.Engine/osx-arm64/thunderscope-calibration.json
  rm ../thunderscope-calibration.json
fi

if test -f ../thunderscope-appsettings.json; then
  cp ../thunderscope-appsettings.json ../builds/TS.NET.Engine/osx-arm64/thunderscope-appsettings.json
  rm ../thunderscope-appsettings.json
fi

if test -f ../libtslitex.so; then
  cp ../libtslitex.so ../builds/TS.NET.Engine/osx-arm64/libtslitex.so
  rm ../libtslitex.so
fi


